﻿# encoding:utf-8
import requests
import os
# 导入requests_toolbelt库使用MultipartEncoder
from requests_toolbelt import MultipartEncoder
from wxpyImport import *

url = 'http://photo.ds.cn/multiUpload'
headers = {
    'Cookie': 'NTKF_T2D_CLIENTID=guestC8A38220-54B6-AE78-ECF6-850F4E723B18; Qs_lvt_73123=1525227889%2C1525655428%2C1527038722%2C1527307016%2C1528942815; Qs_pv_73123=3328986440424628000%2C217213508423031520%2C2259878596724562200%2C3895206789987362000%2C4146306986917148700; Hm_lvt_7ac741aebc5aaaacab752db97f0969e5=1529651618,1530211164,1531204566,1531359294; _ga=GA1.2.1209097419.1535447518',
    'Host': 'photo.ds.cn',
    'Origin': 'http://photo.ds.cn',
    'Referer': 'http://photo.ds.cn/image',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
    }
image_filename = os.path.basename('jpg.jpg')
file_payload = {
    'app':'image',
    'uploadFile': (image_filename, open('jpg.jpg', 'rb'))
    }
# 生成可用于multipart/form-data上传的数据
m = MultipartEncoder(file_payload)
# 自动生成Content-Type类型和随机码
headers['Content-Type'] = m.content_type
# 使用data上传文件
html = requests.post(url, headers=headers, data=m)
logInfo(html.json())
logInfo(html.json()['data']['oURL'])